package edu.base.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.base.util.HigherResponse;
import edu.base.dao.RecEqptDao;
import edu.base.dao.RecOrderDao;
import edu.base.entity.RecordEquipment;
import edu.base.entity.vo.RecordOrderVO;
import edu.base.util.UUIDUtils;

@Service
public class RecOrderServiceImpl implements RecOrderService{

	@Autowired
	private RecEqptDao recEqptDao;
	@Autowired
	private RecOrderDao recOrderDao;
	private Long orderId;
	
	//添加客户确认单
	@Override
	public HigherResponse<String> addRecOrder(Integer repId, String userName, String userMobilephone) {
		//生成订单号
		orderId=Long.parseLong(UUIDUtils.getUUID16());
		//System.out.println(orderId.getClass().getName());
		System.out.println(orderId);
		//根据报修id查询报修设备id
		List<RecordEquipment> eqptRec=recEqptDao.queryEqptByProdType(repId,null);
		if(eqptRec.size()==0) {
			return HigherResponse.getFailedRespon("无记录");
		}
		Integer eqptId=eqptRec.get(0).getId();
		RecordOrderVO recOrder=new RecordOrderVO(orderId,repId,eqptId,userName,userMobilephone);
		//添加确认单
		int flag=recOrderDao.addOneOrder(recOrder);
		if(0==flag) {
			return HigherResponse.getFailedRespon("客户确认单添加失败");
		}
		return HigherResponse.getSuccessRespon("客户确认单添加成功");
	}
	
	/*	
	 * 打印客户确认单
	 */
	@Override
	public HigherResponse<RecordOrderVO> queryOrder() {
		List<RecordOrderVO> recordOrderVOs=recOrderDao.queryRecOrder(orderId);
		System.out.println(orderId);
		if(recordOrderVOs.size()==0) {
			return HigherResponse.getFailedRespon("无记录");
		}
		RecordOrderVO recOrder=recordOrderVOs.get(0);
		System.out.println(recOrder);
		return HigherResponse.getSuccessRespon(recOrder);
	}
	
	/*	
	 * 打印客户确认单
	 */
	@Override
	public RecordOrderVO queryOrder2() {
		//System.out.println(orderId.getClass().getName());
		System.out.println(orderId);
		List<RecordOrderVO> recordOrderVOs=recOrderDao.queryRecOrder(orderId);
		if(recordOrderVOs.size()==0) {
			return null;
		}
		RecordOrderVO recOrder=recordOrderVOs.get(0);
		System.out.println(recOrder);
		return recOrder;
	}

}
